﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data;
using BlueCMS.Core.Data.Query;
using BlueCMS.Core.Entities;

namespace BlueCMS.Core.Services
{
    public class NodeService : ServiceBase 
    {
        public static Node GetNodeForWebsiteAndPath(Website website, string path)
        {
            SelectQuery query = new SelectQuery();
            query.From.Table("cms_node_tbl");
            query.Where
                .Column("website_id").Equals().Parameter(website.website_id)
                .And()
                .Column("path").Equals().Parameter(path)
                .And()
                .Column("isactive").Equals().Constant(true)
                .And()
                .Column("isdeleted").Equals().Constant(false);

            return query.ExecuteObject<Node>();
        }

        public static NodeType GetNodeTypeForNode(Node node)
        {
            SelectQuery query = new SelectQuery();
            query.From.Table("cms_nodetype_tbl");
            query.Where.Column("nodetype_id").Equals().Parameter(node.nodetype_id);

            return query.ExecuteObject<NodeType>();
        }
    }
}
